package com.jdls.day16.work;

/**
 * @author 嘉德罗斯
 * @date 2021/8/7
 */
public class Test3 {
    public static void main(String[] args) {
        //3. 使用wait和notify完成吃汉堡的案例
        new Thread(()->{
            while (true){
                synchronized (Task.class){
                    if(!Task.a){
                        System.out.println("做");
                        Task.a = true;
                        Task.class.notifyAll();
                    }else {
                        try {
                            Task.class.wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        }).start();
        new Thread(()->{
            while (true){
                synchronized (Task.class){
                    if(Task.a){
                        System.out.println("吃");
                        Task.a = false;
                        Task.class.notifyAll();
                    }else {
                        try {
                            Task.class.wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        }).start();
    }
}
class Task{
    public static boolean a = false;
}
